package org.algorithm.熊猫.链表;

import com.sun.tools.javac.util.Assert;
import org.algorithm.common.ListNode;
import org.junit.Test;

/**
 * good luck guys
 * keep learing for algorithm
 *
 * 链表注重 数据衔接，头尾判空。 指针指向。
 *
 * @Link {https://leetcode-cn.com/problems/fan-zhuan-lian-biao-lcof/}
 */
public class 反转链表 {

    @Test
    public void test() {
        ListNode node = ListNode.build(6, 5, 4, 3, 2, 1);
        ListNode listNode = reverseList(node);
        ListNode.print(listNode);
    }

    public static ListNode reverseList(ListNode node) {
        ListNode head = null;
        while (node != null) {
            ListNode next = node.next;
            node.next = head;
            head = node;
            node = next;
        }
        return head;
    }


}
